<?php
namespace app\common\model;

class Category extends BaseModel{

	public function getImgUrlAttr($images_id = '', $data = array()){
		
		$images_id = $images_id ? $images_id : $data['images_id'];
		$img_url = model('File')->get_path($images_id);

		return $img_url ? $img_url : '';
	}
	/**
	 * 获取类别名称
	 * @param  [type] $category_id 类别ID
	 */
	public function getName($category_id){
		if(!$category_id){
			return '';
		}
		$name_arr = $this->where('category_id', 'in', $category_id)->column('title');
		$name_str = implode(',', $name_arr);

		return $name_str ? $name_str : '';
	}
	/**
	 * 获取类别清单
	 * @param  string $module    模块
	 * @param  string $limit     数量
	 * @param  string $parent_id 父ID
	 */
	public function getCategoryList($module = '', $limit = '', $parent_id = ''){
		$where['module'] = $module;
		if($parent_id){
			$where['parent_id'] = $parent_id;
		}
		$list = $this->where($where)->order('order_id,category_id desc')->limit($limit)->select();

		return $list ? $list : array();
	}
}